/*
 * @Description: 过滤器
 * @Author: zheng yiliang
 * @Date: 2021-05-09 21:40:42
 * @LastEditTime: 2021-05-26 23:02:48
 * @LastEditors: zheng yiliang
 */

import dayjs from 'dayjs'
import Vue from 'vue'

export function dateSlice (val, index) {
  const date = dayjs(val).format('YYYYMMDD')
  if (index === 'YYYY') return date.slice(0, 4)
  if (index === 'MM') return date.slice(4, 6) * 1
  if (index === 'DD') return date.slice(-2)
  return date
}

export function dateTime (val) {
  return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
}

export function dateChina (val, date = 'YYYY年MM月DD') {
  return dayjs(val).format(date)
}

export function commentDate (val) {
  return dayjs(val).format('YYYY/MM/DD HH:mm:ss')
}

Vue.filter('dateSlice', dateSlice)
Vue.filter('dateTime', dateTime)
Vue.filter('dateChina', dateChina)
Vue.filter('commentDate', commentDate)

